package com.sukaiyi.generator.config;

import com.sukaiyi.generator.config.defaulttpl.DefaultTemplate;
import com.sukaiyi.generator.config.model.StructTemplate;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sukaiyi
 */
@State(name = "IdeaCodeGenerator", storages = {@com.intellij.openapi.components.Storage(value = "$APP_CONFIG$/IdeaCodeGenerator.xml")})
public class PluginConfig implements PersistentStateComponent<PluginConfig> {

    public boolean generateLombokVO = true;
    public boolean voJsonFormat = false;

    public List<StructTemplate> templates = DefaultTemplate.load();

    public Map<String, String> globalVariable = new HashMap<String, String>(){{
        put("user", System.getProperty("user.name"));
        put("date", "[Dynamic]");
    }};

    @Nullable
    @Override
    public PluginConfig getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull PluginConfig pluginConfig) {
        XmlSerializerUtil.copyBean(pluginConfig, this);
    }

    public static PluginConfig getInstance() {
        return ServiceManager.getService(PluginConfig.class);
    }
}
